package cn.mandifal.login.service;

import cn.mandifal.pojo.DpUser;
import cn.mandifal.user.service.UserService;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.ArrayList;
import java.util.List;

public class UserDetailsServiceImpl implements UserDetailsService {

    /**
     * 注入用户服务 bean
     */
//    private UserService userService;
//
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //定义角色列表，声明只有 ROSE_SELLER的角色用户才能登陆
        List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
        grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));
        //得到用户
         //DpUser oneUser = userService.findOneUser(username);
//        if (oneUser !=null){
//            //如果用户名和密码都正确就返回用户
//            return new User(username,oneUser.getPassword(), grantedAuths);
//        }else{
//            return null;
//        }
        return new User(username,"", grantedAuths);

    }
}
